package com.connect.agreement;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;

public class Compress {
	private Deflater deflater = new Deflater();
	/**
	* 压缩字节
	* @param input
	* @return
	* @throws IOException
	*/
	public byte[] compress(byte[] input){
		try {
			deflater.reset();
			deflater.setInput(input);
			deflater.finish();
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream(input.length);
			byte[] buf = new byte[1024];
			int len;
			while(!deflater.finished()){
			   len = deflater.deflate(buf);
			   outputStream.write(buf,0,len);
			}
			byte[] tmpByte = outputStream.toByteArray();
			outputStream.close();
			return tmpByte;
		} catch (Exception e) {
			return input;
		}
		
	} 
}
